package com.cdut.drivingschool.http.parser;
import org.json.JSONException;
import org.json.JSONObject;

import com.cdut.drivingschool.bean.BaseType;
import com.cdut.drivingschool.exception.ParserException;
/**
 * 基础解析器
 * @author Administrator
 *
 */
public abstract class BaseParser implements Parser{
	@Override
	public BaseType parser(String json) throws ParserException {
		try {
			JSONObject object = new JSONObject(json);
			if(object.getInt("code") != SUCCESS_CODE){
				throw new ParserException(object.getString("msg"));
			}else{
				return parserObject(object.getString("data"));
			}
		} catch (JSONException e) {
			throw new ParserException("参数解析异常");
		}
	}
	abstract public BaseType parserObject(String json_data) throws ParserException;
}
